home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWString / Include / FWStrToo.h < prev   
Encoding:
C/C++ Source or Header  |  1995-11-08  |  9.8 KB  |  282 lines  |  [TEXT/MPS ]

  1. #ifndef FWSTRTOO_H
  2. #define FWSTRTOO_H
  3. //========================================================================================
  4. //
  5. //    File:                FWStrToo.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWEXCDEF_H
  13. #include "FWExcDef.h"
  14. #endif
  15.  
  16. #ifndef FWSTRS_H
  17. #include "FWStrs.h"
  18. #endif
  19.  
  20. #if FW_LIB_EXPORT_PRAGMAS
  21. #pragma lib_export on
  22. #endif
  23.  
  24. //========================================================================================
  25. //    CLASS FW_CStringTool
  26. //
  27. //        A tool for string operations.  StringTools are used for operations that don't fit
  28. //        well as methods of strings.  The principle reason for placing an operation in a 
  29. //        tool instead of a string is when the operation may have multiple algorithm 
  30. //        implementations.  We make this distinction because it is undesirable to force
  31. //        a user to subclass one or more string classes just to use a different set of
  32. //        tool algorithms.
  33. //
  34. //        Note that "StringTool" is only one kind of "string tool".  Other string tools
  35. //        include translation tools, format tools, etc.  This StringTool class is intended
  36. //        for "pure string" manipulation, e.g. searching and comparing.
  37. //
  38. //        The FW_CStringTool class is an abstract base class.
  39. //========================================================================================
  40.  
  41. enum FW_StringCompareResult
  42. {
  43.     kStringOneLess = -1, kStringsEqual = 0, kStringOneGreater = 1
  44. } ;
  45.  
  46. // Note: The following enumeration should be class scoped, but Borland croaks later
  47. // on if this is class scoped.
  48.  
  49. enum FW_FindDirection { FW_kForwards, FW_kBackwards };
  50.  
  51. class FW_CLASS_ATTR FW_CStringTool FW_AUTO_DESTRUCT_OBJECT
  52. {
  53.   public:
  54.  
  55.     virtual ~ FW_CStringTool();
  56.     FW_CStringTool(FW_Boolean caseSensitive=TRUE);
  57.     
  58.     FW_Boolean SetCaseSensitivity(FW_Boolean caseSensitive);
  59.         // Sets the sensitivity, returns prior sensitivity
  60.  
  61.     FW_StringCompareResult CompareStrings(FW_CTextReader &reader1,
  62.                                            FW_CTextReader &reader2);
  63.                                          
  64.     FW_StringCompareResult CompareStrings(const FW_CString &string1,
  65.                                            const FW_CString &string2);
  66.     
  67.     FW_Boolean FindSubString(FW_CTextReader &reader,
  68.                              const FW_CString &subString,
  69.                              FW_CharacterPosition &foundPosition);
  70.                                      
  71.     FW_Boolean FindSubString(const FW_CString &string,
  72.                              const FW_CString &subString,
  73.                              FW_CharacterPosition &foundPosition,
  74.                              FW_CharacterPosition startPosition=0);
  75.                                      
  76.     FW_Boolean FindCharacter(FW_CTextReader &reader,
  77.                              FW_LChar character,
  78.                              FW_CharacterPosition &foundPosition,
  79.                              FW_FindDirection direction=FW_kForwards);
  80.                                  
  81.     FW_Boolean FindCharacter(const FW_CString &string,
  82.                              FW_LChar character,
  83.                              FW_CharacterPosition &foundPosition,
  84.                              FW_CharacterPosition startPosition=0,
  85.                              FW_FindDirection direction=FW_kForwards);
  86.                                     
  87.     FW_Boolean IsWhiteSpace(FW_LChar character);
  88.                                  
  89.     FW_Boolean IsWhiteSpace(FW_CTextReader &reader);
  90.                                  
  91.     FW_Boolean FindWhiteSpace(FW_CTextReader &reader,
  92.                               FW_CharacterPosition &foundPosition,
  93.                               FW_FindDirection direction=FW_kForwards);
  94.                                  
  95.     FW_Boolean FindWhiteSpace(const FW_CString &string,
  96.                               FW_CharacterPosition &foundPosition,
  97.                               FW_CharacterPosition startPosition=0,
  98.                               FW_FindDirection direction=FW_kForwards);
  99.                                          
  100.     FW_Boolean FindNonWhiteSpace(FW_CTextReader &reader,
  101.                                  FW_CharacterPosition &foundPosition,
  102.                                  FW_FindDirection direction=FW_kForwards);
  103.  
  104.     FW_Boolean FindNonWhiteSpace(const FW_CString &string,
  105.                                  FW_CharacterPosition &foundPosition,
  106.                                  FW_CharacterPosition startPosition=0,
  107.                                  FW_FindDirection direction=FW_kForwards);
  108.                                          
  109.     FW_Boolean Substitute(FW_CString &string,
  110.                           const FW_CString &searchString,
  111.                           const FW_CString &substitutionString);
  112.     
  113.     void ToUpper(FW_CTextReader &input, FW_CTextWriter &output);
  114.     
  115.     void ToUpper(FW_CString &string);
  116.     
  117.     void ToLower(FW_CTextReader &input, FW_CTextWriter &output);
  118.  
  119.     void ToLower(FW_CString &string);
  120.                                      
  121.     // ----- Static functions for accessing default and current string tools.
  122.  
  123.     static FW_CStringTool* GetCurrentStringTool();
  124.         // Return a pointer to the current string tool.
  125.         
  126.     static FW_CStringTool* SetCurrentStringTool(FW_CStringTool* tool);
  127.         // Make tool the current string tool.
  128.         // Returns the prior string tool.
  129.  
  130.   protected:
  131.     
  132.     virtual FW_StringCompareResult DoCompareStrings(FW_CTextReader &reader1,
  133.                                                      FW_CTextReader &reader2) = 0;
  134.                                          
  135.     virtual FW_Boolean DoMatchPrefixString(FW_CTextReader &target,
  136.                                             FW_CTextReader &prefix) = 0;
  137.                                          
  138.     virtual FW_Boolean DoFindSubString(FW_CTextReader &searchStringReader,
  139.                                        FW_CTextReader &subStringReader,
  140.                                        FW_CharacterPosition &foundPosition) = 0;
  141.                                      
  142.     virtual FW_Boolean DoFindCharacter(FW_CTextReader &reader,
  143.                                        FW_LChar character,
  144.                                        FW_CharacterPosition &foundPosition,
  145.                                        FW_FindDirection direction=FW_kForwards) = 0;
  146.                                  
  147.     virtual FW_Boolean DoFindWhiteSpace(FW_CTextReader &reader,
  148.                                         FW_CharacterPosition &foundPosition,
  149.                                         FW_FindDirection direction=FW_kForwards) = 0;
  150.                                  
  151.     virtual FW_Boolean DoFindNonWhiteSpace(FW_CTextReader &reader,
  152.                                            FW_CharacterPosition &foundPosition,
  153.                                            FW_FindDirection direction=FW_kForwards) = 0;
  154.  
  155.     virtual FW_Boolean DoIsWhiteSpace(FW_LChar character) = 0;
  156.                                  
  157.     virtual void DoConvertToUpper(FW_Char *chars, FW_CharacterCount length) = 0;
  158.     
  159.     virtual void DoConvertToLower(FW_Char *chars, FW_CharacterCount length) = 0;
  160.  
  161.     FW_Boolean fCaseSensitive;
  162.  
  163. private:
  164.  
  165.     static FW_CStringTool*& GetTool();
  166.     
  167. };
  168.  
  169. //----------------------------------------------------------------------------------------
  170. //    FW_CStringTool::CompareStrings
  171. //----------------------------------------------------------------------------------------
  172.  
  173. inline FW_StringCompareResult FW_CStringTool::CompareStrings(
  174.                                         FW_CTextReader &reader1,
  175.                                          FW_CTextReader &reader2)
  176. {
  177.     return DoCompareStrings(reader1, reader2);
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    FW_CStringTool::FindCharacter
  182. //----------------------------------------------------------------------------------------
  183.  
  184. inline FW_Boolean FW_CStringTool::FindCharacter(FW_CTextReader& reader,
  185.                                                 FW_LChar character,
  186.                                                 FW_CharacterPosition& foundPosition,
  187.                                                 FW_FindDirection direction)
  188. {
  189.     return DoFindCharacter(reader, character, foundPosition, direction);
  190. }
  191.  
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CStringTool::IsWhiteSpace
  195. //----------------------------------------------------------------------------------------
  196.  
  197. inline FW_Boolean FW_CStringTool::IsWhiteSpace(FW_LChar character)
  198. {
  199.     return DoIsWhiteSpace(character);
  200. }
  201.                                                                  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CStringTool::FindWhiteSpace
  204. //----------------------------------------------------------------------------------------
  205.  
  206. inline FW_Boolean FW_CStringTool::FindWhiteSpace(
  207.                                         FW_CTextReader &reader,
  208.                                         FW_CharacterPosition &foundPosition,
  209.                                         FW_FindDirection direction)
  210. {
  211.     return DoFindWhiteSpace(reader, foundPosition, direction);
  212. }
  213.                                      
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CStringTool::FindNonWhiteSpace
  216. //----------------------------------------------------------------------------------------
  217.  
  218. inline FW_Boolean FW_CStringTool::FindNonWhiteSpace(
  219.                                         FW_CTextReader &reader,
  220.                                         FW_CharacterPosition &foundPosition,
  221.                                         FW_FindDirection direction)
  222. {
  223.     return DoFindNonWhiteSpace(reader, foundPosition, direction);
  224. }
  225.                                      
  226. //========================================================================================
  227. //    CLASS FW_CMinimalStringTool
  228. //
  229. //        A minimalist, braindead string tool.  Operations are done without any knowledge
  230. //        of language, locale, character set, case sensitivity, etc.  This tool is provided
  231. //        for quick and dirty use where lack of such knowledge is not considered a problem.
  232. //        Real applications will need to use more sophisticated string tools, provided in
  233. //        other, higher level components.
  234. //========================================================================================
  235.  
  236. class FW_CLASS_ATTR FW_CMinimalStringTool : public FW_CStringTool
  237. {
  238.   public:
  239.  
  240.     virtual ~ FW_CMinimalStringTool();
  241.     FW_CMinimalStringTool(FW_Boolean caseSensitive=TRUE);
  242.  
  243.   protected:
  244.     
  245.     virtual FW_StringCompareResult DoCompareStrings(FW_CTextReader &reader1,
  246.                                                      FW_CTextReader &reader2);
  247.                                          
  248.     virtual FW_Boolean DoMatchPrefixString(FW_CTextReader &target,
  249.                                             FW_CTextReader &prefix);
  250.                                          
  251.     virtual FW_Boolean DoFindSubString(FW_CTextReader &searchStringReader,
  252.                                        FW_CTextReader &subStringReader,
  253.                                        FW_CharacterPosition &foundPosition);
  254.                                      
  255.     virtual FW_Boolean DoFindCharacter(FW_CTextReader &reader,
  256.                                        FW_LChar character,
  257.                                        FW_CharacterPosition &foundPosition,
  258.                                        FW_FindDirection direction=FW_kForwards);
  259.                                  
  260.     virtual FW_Boolean DoFindWhiteSpace(FW_CTextReader &reader,
  261.                                         FW_CharacterPosition &foundPosition,
  262.                                         FW_FindDirection direction=FW_kForwards);
  263.                                  
  264.     virtual FW_Boolean DoFindNonWhiteSpace(FW_CTextReader &reader,
  265.                                            FW_CharacterPosition &foundPosition,
  266.                                            FW_FindDirection direction=FW_kForwards);
  267.  
  268.     virtual FW_Boolean DoIsWhiteSpace(FW_LChar character);
  269.                                  
  270.     virtual void DoConvertToUpper(FW_Char *chars, FW_CharacterCount length);
  271.     virtual FW_LChar ConvertToUpper(FW_LChar character);
  272.     
  273.     virtual void DoConvertToLower(FW_Char *chars, FW_CharacterCount length);
  274.  
  275. };
  276.  
  277. #if FW_LIB_EXPORT_PRAGMAS
  278. #pragma lib_export off
  279. #endif
  280.  
  281. #endif
  282.